home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / hsv.pro < prev    next >
Encoding:
Text File  |  1997-07-08  |  2.5 KB  |  89 lines

  1. ; $Id: hsv.pro,v 1.3 1997/01/15 03:11:50 ali Exp $
  2. ;
  3. ; Copyright (c) 1983-1997, Research Systems, Inc.  All rights reserved.
  4. ;    Unauthorized reproduction prohibited.
  5.  
  6. Pro HSV, Vlo, Vhi, Satlo, Sathi, Hue, Loops, Colr
  7. ;+
  8. ; NAME:
  9. ;    HSV
  10. ;
  11. ; PURPOSE:
  12. ;    Make a color table based on the HSV (Hue, Saturation, and Value) 
  13. ;    color system.
  14. ;
  15. ; CATEGORY:
  16. ;    Z4 - Image processing, color table manipulation
  17. ;
  18. ; CALLING SEQUENCE:
  19. ;    HLS, Vlo, Vhi, Satlo, Sathi, Hue, Loops [, Colr]
  20. ;
  21. ; INPUTS:
  22. ;    Vlo:    Starting value, from 0 to 100%.
  23. ;
  24. ;    Vhi:    Ending value, from 0 to 100%.
  25. ;
  26. ;    Satlo:    Starting saturation, from 0 to 100%.
  27. ;
  28. ;    Sathi:    Ending saturation, from 0 to 100%.
  29. ;
  30. ;    Hue:    Starting Hue, from 0 to 360 degrees.  Red = 0 degs,
  31. ;        green = 120, blue = 240.
  32. ;
  33. ;     Loops:    The number of loops through the color spiral.  This
  34. ;        parameter does not have to be an integer.  A negative value
  35. ;        causes the loops to traverse the spiral in the opposite
  36. ;        direction.
  37. ;
  38. ; OUTPUTS:
  39. ;    No required outputs.
  40. ;
  41. ; OPTIONAL OUTPUT PARAMETERS:
  42. ;    Colr:    A (256,3) integer array containing the R, G, and B values
  43. ;        that were loaded into the color tables.
  44. ;        Red = colr(*, 0), green = colr(*, 1), blue = colr(*, 2).
  45. ;
  46. ; COMMON BLOCKS:
  47. ;    COLORS:    Contains the red, green and blue color vectors on exit.
  48. ;
  49. ; SIDE EFFECTS:
  50. ;    The color tables are loaded.
  51. ;
  52. ; RESTRICTIONS:
  53. ;    None.
  54. ;
  55. ; PROCEDURE:
  56. ;    Adapted from a program on page 616, Fundamentals of Interactive
  57. ;    Computer Graphics, Foley and Van Dam.
  58. ;
  59. ;    Using the input parameters, a spiral through the single-ended HSV 
  60. ;    cone is traced.  Points along the cone are converted from HLS to RGB.
  61. ;
  62. ; MODIFICATION HISTORY:
  63. ;    Written, DMS, Jan, 1983.
  64. ;    Added common block COLORS, DMS, Dec, 1983 and Apr, 1987.
  65. ;-
  66.     common colors,red,green,blue,cur_red,cur_green,cur_blue
  67.     on_error,2                        ;Return to caller if an error occurs
  68.     S = (sathi-satlo)/25600.*findgen(256)+satlo/100.
  69.     V = (Vhi-Vlo)/25600.*findgen(256)+vlo/100.
  70.     H = Loops*360./256.*findgen(256)+ Hue
  71.     Hmin = Min(H)/360.
  72.     IF HMIN LT 0. THEN HMIN = FIX(HMIN)-1 ELSE $
  73.         HMIN =FIX(HMIN)
  74.     H= ((H - Hmin*360.) mod 360.)/60.    ;Sector, 0 to 5.
  75.     IH = FIX(H)
  76.     f=h-ih            ;fractional part
  77.     x = FIX(255.*[[v*(1.-s)],[v*(1.-s*f)],[v*(1.-s*(1.-f))],[v]]);4 choices
  78.     mat = [[3,2,0],[1,3,0],[0,3,2],[0,1,3],[2,0,3],[3,0,1]] ;selector
  79. ;
  80.     colr = intarr(256,3)        ;define tables
  81.     for i=0,255 do $
  82.         if s[i] eq 0. then colr[i,*]=255.*v[i] else $
  83.          for j=0,2 do colr[i,j]=x[i,mat[j,ih[i]]]
  84.     red = colr[*,0] & green = colr[*,1] & blue = colr[*,2]
  85.     tvlct,red,green,blue
  86.     cur_red = red & cur_green = green & cur_blue = blue ;save current clrs
  87.     return
  88. end
  89.